package cn.wolfcode.trip.base.util;

import cn.wolfcode.trip.base.domain.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * 用户登录检查
 */
public class UserContext {
    public static final String USER_IN_SESSION = "USER_IN_SESSION";

    private static HttpSession getSession() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
    }

    public static void setCurrentUser(Map map) {
        getSession().setAttribute(USER_IN_SESSION, map);
    }

    public static Map getCurrentUser() {
        Map map = (Map) getSession().getAttribute(USER_IN_SESSION);
        return map;
    }

    public static void destroy() {
        getSession().invalidate();
    }
}
